package com.tn.bo;

import java.util.Date;

import javax.persistence.Id;
import javax.persistence.Transient;

import com.googlecode.objectify.annotation.Entity;

@Entity
public class UserLoginDetails {
	@Id
	private Long loginProfileId;
	
	private Long userProfileId;
	private String userId;
	private String userPasswordHash;
	@Transient
	private String plainTextPassword;
	@Transient
	private static final String someString = "32138217391";
	private Date lastLogin;
	
	
	public Date getLastLogin() {
		return lastLogin;
	}

	public void setLastLogin(Date lastLogin) {
		this.lastLogin = lastLogin;
	}

	public Long getLoginProfileId() {
		return loginProfileId;
	}

	public void setLoginProfileId(Long loginProfileId) {
		this.loginProfileId = loginProfileId;
	}

	public Long getUserProfileId() {
		return userProfileId;
	}

	public String getUserPasswordHash() {
		return userPasswordHash;
	}

	public void setUserPasswordHash(String userPasswordHash) {
		this.userPasswordHash = userPasswordHash;
	}

	public void setUserProfileId(Long userProfileId) {
		this.userProfileId = userProfileId;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getPlainTextPassword() {
		return plainTextPassword;
	}

	public void setPlainTextPassword(String plainTextPassword) {
		this.plainTextPassword = plainTextPassword;
	}

	public static boolean isAuthenticated(UserLoginDetails details){
		String hash = String.valueOf(details.userId.hashCode() +  someString + details.plainTextPassword.hashCode());
		return details.userPasswordHash.equals(hash);
	}
	
	public static String createUserPasswordHash(UserLoginDetails details){
		return details.userId.hashCode() + someString + details.plainTextPassword.hashCode();
	}
	
	public static String createRegistrationHash(String userId){
		return userId.hashCode() + someString + System.nanoTime();
	}
}
